<template>
  <!-- 已登录 -->
  <div v-if="isLogin">
    <div class="member">
      <div class="user-info">
        <div class="avatar">
          <img src="@/assets/images/avatar_default.png" class="image-info" />
        </div>
        <div class="text-info">
          <span>{{ user.name }}</span>
        </div>
      </div>
    </div>
    <div class="member d-flex justify-content-between">
    <div >
      <router-link :to="{ name: 'order_list' }" class="mui-navigate-right">
        <img width="60" height="60" src="@/assets/images/avatar_default.png" />
        <div class="">我的订单</div>
      </router-link>
    </div>
    <div>
      <router-link :to="{ name: 'address_list' }" class="">
        <img width="60" height="60" src="@/assets/images/avatar_default.png" />
        <div class="mui-media-body">收货地址</div>
      </router-link>
    </div>
    <div>
      <div @click="onClickLogout" class="">
        <img width="60" height="60" src="@/assets/images/avatar_default.png" />
        <div class="mui-media-body">退出登录</div>
      </div>
    </div>
    </div>
  </div>
  <!-- 未登录 -->
  <div v-else>
    <div class="member">
      <router-link :to="{ name: 'login' }" class="">
        <div class="user-info">
          <!-- user-info -->
          <div class="avatar">
            <img src="@/assets/images/avatar_default.png" class="image-info" />
          </div>
          <div class="text-info">
            <!-- person-con -->
            登录 / 注册
          </div>
        </div>
      </router-link>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex"; // mapGetters

export default {
  data() {
    return {
      isLogin0: true,
    };
  },
  computed: {
    ...mapState("user",["user","isLogin"]),     
  },
  methods: {
    async onClickLogout() {
      try {
        let result = await this.$store.dispatch("user/logout");         
        if(result.code == 1){
          this.$toast("退出成功");
        }else{
          throw result.msg;
        } 
      } catch (error) {
        this.$messagebox("退出失败",error);  
      }  
    },
  },
};
</script>

<style lang="scss" scoped>
.member {
  margin-top: 15px;
  padding: 10px;
  background-color: #fff;
  .user-info {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 120px;
    background: linear-gradient(90deg, #28a2ff, #ffd787);
    box-shadow: 0 0.1rem 0.25rem #f8e3c6;
    .avatar {
      position: absolute;
      left: 15px;
      top: 50%;
      transform: translateY(-50%);

      width: 80px;
      height: 80px;
      overflow: hidden;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 15);
      border: 1px solid hsla(0, 0%, 100%, 0.4);
      border-radius: 50% 50%;
      .image-info {
        width: 100%;
        height: 100%;
      }
    }

    .text-info {
      position: absolute;
      left: 120px;
      top: 50%;
      transform: translateY(-50%);
      font-size: 24px;
      color: rgb(65, 16, 241);
    }
  }
}
</style>
